package vertxRestZeebeKafka;

import io.vertx.core.json.JsonObject;
import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;

public class PlusJobWorkerHandler implements JobHandler {
    ZeebeClient zeebeClient;

    public PlusJobWorkerHandler(ZeebeClient client) {
        this.zeebeClient = client;
    }

    @Override
    public void handle(JobClient client, ActivatedJob job) throws Exception {
        System.out.println("开始执行plusJobWorker");

        JsonObject data = new JsonObject(job.getVariables());
        int a=data.getInteger("a");
        int b=data.getInteger("b");
        int c=a+b;
        System.out.println("plusJobWorker执行完成。c="+c);

        JsonObject result=new JsonObject()
                .put("c",c);

        client.newCompleteCommand(job.getKey())
                .variables(result.encode())
                .send()
                .join();
    }
}
